package main

import (
	"strconv"
)

func evalRPN(tokens []string) int {
	stack := []int{}
	for _, token := range tokens {
		v, err := strconv.Atoi(token)
		if err == nil {
			stack = append(stack, v)
		} else {
			num1, num2 := stack[len(stack)-1], stack[len(stack)-2]
			if token == "+" {
				stack[len(stack)-2] = num2 + num1
			} else if token == "-" {
				stack[len(stack)-2] = num2 - num1
			} else if token == "*" {
				stack[len(stack)-2] = num2 * num1
			} else if token == "/" {
				stack[len(stack)-2] = num2 / num1
			}
			stack = stack[:len(stack)-1]
		}
	}
	return stack[0]
}
func main() {
	tokens := []string{"2", "1", "+", "3", "*"}
	evalRPN(tokens)
}
